﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleGame.ScreenManagement.Screens
{
    public class MainMenuScreen : MenuScreen
    {
        #region Constructor

        public MainMenuScreen()
            : base("Main Menu")
        {
            // Create menu items
            MenuItem playGameMenuItem = new MenuItem("New Game");
            MenuItem optionsMenuItem = new MenuItem("Options");
            MenuItem exitMenuItem = new MenuItem("Exit");

            // Hook up menu event handlers
            playGameMenuItem.Selected += PlayGameMenuItemSelected;
            optionsMenuItem.Selected += OptionsMenuItemSelected;
            exitMenuItem.Selected += OnCancel;

            // Add items to the menu
            menuItems.Add(playGameMenuItem);
            menuItems.Add(optionsMenuItem);
            menuItems.Add(exitMenuItem);
        }

        #endregion

        #region Event Handlers

        /// <summary>
        /// Event handler for when the Play Game menu item is selected.
        /// </summary>
        private void PlayGameMenuItemSelected(object sender, EventArgs e)
        {
            screenManager.AddScreen(new GameplayScreen());
            screenManager.RemoveScreen(this);
        }


        /// <summary>
        /// Event handler for when the Options menu item is selected.
        /// </summary>
        private void OptionsMenuItemSelected(object sender, EventArgs e)
        {
            screenManager.AddScreen(new OptionsScreen());
            screenManager.RemoveScreen(this);
        }

        /// <summary>
        /// When the user cancels the main menu, the game exits.
        /// </summary>
        protected override void OnCancel(object sender, EventArgs e)
        {
            screenManager.Game.Exit();
        }

        #endregion
    }
}
